home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_07
/
8n07117a
< prev
next >
Wrap
Text File
|
1990-06-17
|
888b
|
42 lines
/* Listing 2 - Constructor & Destructor Templates */
CLASS *new_CLASS() {
SUPER_CLASS *s;
CLASS *this;
/* Construct super class */
s = new_SUPER_CLASS();
/* Allocate memory for this object */
this = calloc(1,sizeof(CLASS));
/* Inherit everything you can from the superclass */
memmove(this,s,sizeof(CLASS);
/* We're done with the superclass's memory */
free(s);
/* Assign methods to object */
this->f1 = f1;
/* Inialize attributes here. Open files, allocate etc.*/
return(this);
}
void destroy_CLASS(CLASS *this) {
/* Free any specific data: */
free(this->p);
/* Close any files specific to this class: */
fclose(this->file);
/* Call the superclass's destructor */
destroy_SUPER_CLASS(this);
}
void destroy_SUPER_CLASS(SUPER_CLASS *this) {
free(this);
}